@extends('car.base.shopping')

@section('content')
@section('content1')
<form action="shopping" method="get">
    <input type="text" placeholder="请输入商品名称" name="name">
    <button>搜索</button>
</form>
    
@stop
<form method="post" name="myform" action="{{ url('shopping/') }}">
    <input type="hidden" name="_token" value="{{ csrf_token() }}">
    <input type="hidden" name="_method" value="DELETE">
</form>

    <div class="cart-content w1200">
        	<ul class="cart-tit-nav">
            	<li class="current"><a href="#">全部商品 </a></li>
                <div style="clear:both;"></div>
            </ul>
            <div class="cart-con-tit">
            	<p class="p1">
                	<button>全选</button>
    				<span></span>
                </p>
                <p class="p6">商品图片</p>
                <p class="p4">数量</p>
                <p class="p5">单价（元）</p>
                <p class="p6">金额（元）</p>
                <p class="p7">操作</p>
            </div>
        <form action="{{ url('car/order/') }}" name="toorder" method="get">
         <input type="hidden" name="_token" value="{{ csrf_token() }}">
        @foreach ($list as $v)        
            <div class="cart-con-info">
                <div class="info-mid">
                	<input type="checkbox" value="{{ $v->id }}" name="hobby[]" class="mid-ipt f-l"></input>
                    <input type="hidden" name="checkbox_k" value="1">
                    <input type="hidden" name="price" value="1">
                    <div class="mid-tu f-l">
                    	<a href="#"><img src="{{ asset('images') }}/{{ $v->pic }}" /></a>
                    </div>
                    
                    <div class="mid-sl f-l">
                    	<a href="JavaScript:;" class="sl-left">-</a>
                        <input type="text" name="num[]" value="{{ $v->num }}" id="num" />
                        <a href="JavaScript:;" class="sl-right">+</a>
                    </div>
                    <p class="mid-dj f-l">¥ <span>{{ $v->price }}</span></p>
                    <p class="mid-je f-l" >¥ <span>{{ ceil($v->price*$v->num) }}</span>.00</p>
                    <div class="mid-chaozuo f-l">
                    	<a href="#">移入收藏夹</a>
                        <a href="javascript:doDel({{ $v->id }})">删除</a>
                    </div>
                    <div style="clear:both;"></div>
                </div>
            </div>
        @endforeach
                     {{ $list->appends($where)->links() }} 
           	<div class="cart-con-footer">
            	<div class="quanxuan f-l">
                    <a href="#">删除</a>
                    <a href="#">加入收藏夹</a>
                    <p>（此处始终在屏幕下方）</p>
                </div>
                <div class="jiesuan f-r">
                	<div class="jshj f-l">
                    	<p>合计（不含运费）</p>
                    	<p class="jshj-p2">
                        	￥：<span id="price">0</span>.00
                        </p>
                    </div>
                	 <a href="javascript:jieSuan()" class="js-a1 f-l">结算</a> 
</form>
                <div style="clear:both;"></div>
            </div>
            <div style="clear:both;"></div>
        </div>
    </div>
    <script type="text/javascript">
        var ck = '';
        var nck = '';
        function doDel(id)
        {  
             if(confirm('确定要删除吗？')){
                var form = document.myform;
                form.action = 'shopping/'+id;
                form.submit();
            }
        }
        console.log($(":checkbox").length);
        //一个按钮实现全选全不选
        var a = false;
        $("button").click(function(){
            if(!a){
            $(":checkbox").attr("checked",true);
            a = true;
        }else{
             $(":checkbox").attr("checked",false);
            a = false;
        }
         });
        //点击提交，传给控制器用户选中的checkbox值
        function jieSuan(){
            var ids = '';
            var i=0;
            $(':checkbox').each(function(){
            if($(this).attr('checked')){
            ids+=i+',';
            console.log(ids);
           $(':input[name=checkbox_k]').attr('value',ids);
            
        }
        i++;
    });
            var or = document.toorder;
            or.action = 'order/';
            or.submit();
            
        }
    //获取单一商品总价的节点，ajax
    $(':checkbox').change(function(){
        console.log(ck);
        if($(this).attr('checked')){
            ck += $(this).next().next().next().next().next().next().children().text()+',';
        }else{
            nck += $(this).next().next().next().next().next().next().children().text()+',';
        }
        $.ajax({
            url:'/car/aja',
            async:false,                //是否异步
            type:'post',                 //请求方式
            data:{ck:ck,nck:nck,'_token': $('input[name=_token]').val()},              //发送的数据
            dataType:'json',            //响应的数据类型
            error:function()            //失败时回调函数
            {
                alert('ajax请求失败');
            },
            success:function(data)      //成功时回调函数
            {
                console.log(data);
                $("#price").text(data);
               // $(".price").val(data);
                $(':input[name=price]').attr('value',data);
                
            }
        });
    });
   $('.pagination').find('li').css({"font-size":"23px","background":"#63a61d none repeat scroll 0 0","height": "35px","line-height":"35px","width": "41px","float":"left"});
    
 
 </script>



@stop